require(["common","jQuery","coAjax","queryString","href","hash_routie"],function(jSouper,$,coAjax,QueryString,href,hash_routie){
	var _num = 10;
	var _page = 0;
	function _load_eval_page(num,page){
		coAjax.get(appConfig.bus.evaluation_with_page_info,{
			num:num,
			page:page
		},function (result) {
			var info = result.result;
			console.log("bus.evaluations",info.evaluations);
			App.set("bus.evaluations",info.evaluations);
			page_info = {
				total_num:info.total_num,
				total_page:info.total_page,
				page:info.page,
				num:info.num
			};
			page_info._number_list = [];
			page_info._number_list.length = info.total_page;
			App.set("$Cache.bus.eval.page_info",page_info);
		});
	}
	App.set("$Event.bus.eval.change_page",function (e,vm) {
		hash_routie.hash({
			num:_num,
			page:vm.get("$Index")
		});
	});
	//分页功能
	hash_routie.on("evaluation",function () {
		var queryString = new QueryString(location.hash);
		_num = queryString.get("num")||_num;
		_page = queryString.get("page")||_page;
		_load_eval_page(_num,_page);
	});


	//回复评价
	App.set("$Event.eval.reply_eval",function (e,vm) {
		var reply_content = $.trim(App.get("$Cache.eval.reply_content"));
		if (!reply_content) {
			return
		}
		coAjax.post(appConfig.bus.add_comment,{
			reply_id:vm.get("comment_id"),
			content:reply_content
		},function (result) {
			var comments = vm.get("comment.comments");
			comments.unshift(result.result);
			vm.set("comment.comments",comments);
		});
	});
	//接口实现，回复评论
	App.set("$Event.comment.reply",function (e,vm) {
		var _reply_content = $.trim(vm.get("_reply_content"));
		if (!_reply_content) {
			return
		}
		coAjax.post(appConfig.bus.add_comment,{
			reply_id:vm.get("_id"),
			content:_reply_content
		},function (result) {
			var comments = vm.get("comments");
			comments.unshift(result.result);
			vm.set("comments",comments)
		});
	});
});